/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csse3004.GD.PC;

import csse3004.GD.DA.PollCreatorDA;
import csse3004.GD.Question;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author Lewis Kelly 42007689
 */
@ Controller
public class viewQuestionsController {

    protected final Log logger = LogFactory.getLog(getClass());
    private PollCreatorService pollCreatorService = new PollCreatorDA();
    String fail = "No Questions";
    ModelAndView thing = new ModelAndView("viewQuestions", "fail", fail);

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView handleRequest(HttpSession session, HttpServletRequest hsr) throws Exception {
        if (hsr.getParameter("pid") != null) {
            ArrayList<Question> qList2 = new ArrayList<Question>();
            int things = Integer.parseInt(hsr.getParameter("pid"));
            qList2 = pollCreatorService.getQuestions(things);
            ModelAndView mnv = new ModelAndView("viewQuestions", "questions", qList2);
            mnv.addObject("ppid", things);
            return mnv;
        } else {
            return thing;
        }
    }

}
